import requests
import json
import re
# 格式化打印
from pprint import pprint

url='https://vd6.l.qq.com/proxyhttp'
headers = {
    'Cookie':'RK=9yH0RYemEA; ptcz=906ec532877f7635ad30242546e6dc51e0b9bfa6d05873ea8856ac1e14cd086a; qq_domain_video_guid_verify=8fba17201e069e47; _qimei_uuid42=18b16171f0710058eea04fa94c7b413df9c3a9e278; pgv_pvid=6415311509; _qimei_fingerprint=8c6d3b400d828b5aa48094d943725a13; _qimei_h38=19c5dcb7eea04fa94c7b413d0200000d018b16; appuser=63ECF3BD66BFA43A; pac_uid=0_AZrzieaYzi9rw; lv_play_index=41; o_minduid=OyUb-p3BH-KPTU6iFOwidU9D_s_FsxJ6; pgv_info=ssid=s527375840; _qimei_q32=aeeae4b0b7461d4e86dc06cab503cc86; _qimei_q36=cb2615daecf18dbc4fe656a0300019e18b0d; vversion_name=8.2.95; video_omgid=8fba17201e069e47; Lturn=42; LKBturn=189; LPVLturn=830',
    'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0'
}
# 请求参数
data = {
  "buid": "onlyad",
  "vinfoparam": "charge=0&otype=ojson&defnpayver=3&spau=1&spaudio=0&spwm=1&sphls=2&host=v.qq.com&refer=https%3A%2F%2Fv.qq.com%2Fx%2Fcover%2Fmzc00200mnco4mw%2Fp4100lv2bw4.html&ehost=https%3A%2F%2Fv.qq.com%2Fx%2Fcover%2Fmzc00200mnco4mw%2Fp4100lv2bw4.html&sphttps=1&encryptVer=9.2&cKey=uLPkPhyRzKG1PM1Orq2-LnCjnpb8Ocr0cPTenEDpzEul_f4uOWcoVGJNR8Go67M9PQ9FhBZIkmr_Cp7VHCeQghpmp7rG5tiHjLv_PnnatnPaZfOXktuBpd_IleA4_NCYnl3x-IIK4Z0gFjOj-NmZhE-NjjawCzIdF66cdsFdzz5jk70UOmynTHDptaxqIemxrSlkg-M_BbDaBoWwiX7uSsBkDLrqyewGsSa2RgngmgSMgznHp_G95k2a33m3zUyTyqeaEObZjbMFjEGHr7hx7-QqnHySPBbkm4Tp43tKEttzPdfN1LzCquvvxbulqoUFecB0wfll-YSlPPCp0Mk-5bwP1pj6P7lZLKCnd79DmMC5tARSYTcLyPdSGx0AiFgnALIgJ7JSP-AniY1x7r5nw6P3Zobb1YKKkAec1YRzho9eg8WZNVKU1vXC9H305fUQdu-uoiHPcJ5WEwc08zudyhVOo-6L4VkXSIXoG93wMIHfYt3wwcC-D8MmFiXdHSFIFNy4XyhHEhY9_aZFakmoYAgICAgICAgIR7y8qg&clip=4&guid=8fba17201e069e47&flowid=0ffd31701ea43b77eadb9f686b0bae0b&platform=10201&sdtfrom=v1010&appVer=1.36.3&unid=&auth_from=&auth_ext=&vid=p4100lv2bw4&defn=&fhdswitch=0&dtype=3&spsrt=2&tm=1733856571&lang_code=0&logintoken=&spvvpay=1&spadseg=3&spvvc=3&spav1=15&hevclv=28&spsfrhdr=0&spvideo=0&spm3u8tag=67&spmasterm3u8=3&track=undefined&drm=296",
  "sspAdParam": "{\"ad_scene\":1,\"pre_ad_params\":{\"ad_scene\":1,\"user_type\":0,\"video\":{\"base\":{\"vid\":\"p4100lv2bw4\",\"cid\":\"mzc00200mnco4mw\"},\"is_live\":false,\"type_id\":2,\"referer\":\"https://cn.bing.com/\",\"url\":\"https://v.qq.com/x/cover/mzc00200mnco4mw/p4100lv2bw4.html\",\"flow_id\":\"0ffd31701ea43b77eadb9f686b0bae0b\",\"refresh_id\":\"da8922bc27ec123e635920c91b818c50_1733853139\",\"fmt\":\"hd\"},\"platform\":{\"guid\":\"8fba17201e069e47\",\"channel_id\":0,\"site\":\"web\",\"platform\":\"in\",\"from\":0,\"device\":\"pc\",\"play_platform\":10201,\"pv_tag\":\"cn_bing_com\",\"support_click_scan_integration\":true},\"player\":{\"version\":\"1.36.3\",\"plugin\":\"4.1.20\",\"switch\":1,\"play_type\":\"0\"},\"token\":{\"type\":0,\"vuid\":0,\"vuser_session\":\"\",\"app_id\":\"\",\"open_id\":\"\",\"access_token\":\"\"},\"req_extra_info\":{\"now_timestamp_s\":1733856571,\"ad_frequency_control_time_list\":{\"full_pause_short_bid_forbid_cid\":{\"ad_frequency_control_time_list\":[1732289553]},\"full_pause_short_bid_forbid_vid\":{\"ad_frequency_control_time_list\":[1732289553]}}},\"extra_info\":{}}}",
  "adparam": "adType=preAd&vid=p4100lv2bw4&sspKey=refv"
}

res = requests.post(url=url, json=data, headers=headers)
# 获取响应数据
json_data = res.json()
# 视频数据都在vinfo里面
vinfo = json_data['vinfo']
# 把json字符串转换成json字典
vinfo_json = json.loads(vinfo)

# 提取m3u8链接
# m3u8_url = vinfo_json['vl']['vi'][0]['ul']['ui'][-1]['url']
m3u8_uri = re.search('"url":"(.+?index.m3u8)"', vinfo_json).group(1).replace('\\', '')
pprint(json_data)